/*
 * @lc app=leetcode id=478 lang=cpp
 *
 * [478] Generate Random Point in a Circle
 */

// @lc code=start
class Solution {
public:
    Solution(double radius, double x_center, double y_center) {
        radius_ = radius;
        x_center_ = x_center;
        y_center_ = y_center;
        sx_ = x_center_ - radius;
        ex_ = x_center_ + radius;
        sy_ = y_center_ - radius;
        ey_ = y_center_ + radius;
    }
    
    vector<double> randPoint() {
    
        double r, x, y;
        while(true) {
            x = sx_ + static_cast <double> (rand()) /( static_cast <double> (RAND_MAX/(ex_-sx_)));
            y = sy_ + static_cast <double> (rand()) /( static_cast <double> (RAND_MAX/(ey_-sy_)));
            double dx = x - x_center_;
            double dy = y - y_center_;
            r = dx * dx + dy * dy;
            if (r <= radius_ * radius_) {
                break;
            }
        } 
        vector<double> points;
        points.push_back(x);
        points.push_back(y);
        return points;

    }

    double radius_;
    double x_center_;
    double y_center_;
    double sx_;
    double ex_;
    double sy_;
    double ey_;
};

/**
 * Your Solution object will be instantiated and called as such:
 * Solution* obj = new Solution(radius, x_center, y_center);
 * vector<double> param_1 = obj->randPoint();
 */
// @lc code=end

